﻿using CommunityToolkit.Mvvm.Input;
using dpa.Library.Services;

namespace dpa.Library.ViewModels;

public partial class InitializationViewModel(
    IPoetryStorage poetryStorage,
    IRootNavigationService rootNavigationService,
    IMenuNavigationService menuNavigationService,
    IFavoriteStorage favoriteStorage) : ViewModelBase
{
    [RelayCommand]
    private async Task OnInitializedAsync()
    {
        if (!poetryStorage.IsInitialized)
        {
            await poetryStorage.InitializeAsync();
        }

        if (!favoriteStorage.IsInitialized)
        {
            await favoriteStorage.InitializeAsync();
        }

        await Task.Delay(1000);

        rootNavigationService.NavigateTo(RootNavigationConstant.MainView);
        menuNavigationService.NavigateTo(MenuNavigationConstant.TodayView);
    }
}